home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
SWAG
/
SWAGA_C
/
COMM.SWG
/
0088_YModem Code.pas
< prev
Wrap
Pascal/Delphi Source File
|
1995-05-26
|
5KB
|
149 lines
{
> HI, I over heard a message about pascal zmodem/xmodem/ymodem etc.
Actually it's really really big, so i'll post a bit for one of the
ymodem's, plus i think i have to post a unit..
}
FUNCTION SENDYMODEM( filename : string; var f : file ) : boolean;
CONST NULL = $0;
VAR block : array[0..1023] of byte; (* byte *)
temp : string[5];
j,i : integer;
str1 : string;
ftime : longint;
tcrc : word;
dt : datetime;
blocknum,
counter,
result : integer;
BEGIN
(* Build Ymodem header block - block 0 *)
FillChar(sector,SizeOf(sector),NULL); { chr(0) }
for j := 0 to length(filename)-1 DO sector[j] := Ord(filename[j+1]);
inc(j);
str(FileSize(f),str1);
for i := 1 to length(str1) DO sector[j+i] := Ord(str1[i]);
j := j + i + 1;
sector[j] := $20;
GetFTime(f,ftime);
UnPackTime(ftime,dt);
str1 := Octal(Since70(dt));
For i := 1 to length(str1) do sector[j+i] := Ord(str1[i]);
sector[j+i+1] := $20;
(* Send header packet *)
REPEAT
Send(SOH);
Send(#0);
Send(#$FF);
SendBlk(seg(sector[0]),ofs(sector[0]),128);
crc := 0;
crca(Sector,SizeOf(sector),crc);
Send(CHR(Hi(crc)));
Send(CHR(Lo(crc)));
PurgeLine;
UNTIL (readline(10) = Ord(ACK));
blocknum := 1;
str((filesize(f) DIV 1024):5,temp);
WriteLn('File open:' + temp + ' records.');
REPEAT
counter := 0;
FillChar(block,SizeOf(block),CPMEOF);
{$I-} blockread(f,block,SizeOf(block),result); {$I+}
if IOResult <> 0 then
begin
WriteLn('Error Reading File: CANCELLED');
FOS.Send(CAN);
FOS.Send(CAN);
Exit;
end;
REPEAT
Write(cr,'Sending block: ',blocknum);
Send(STX);
Send(CHR(blocknum));
Send(CHR(-blocknum-1));
SendBlk(seg(block[0]),ofs(block[0]),1024);
crc := 0;
Crca(block,sizeof(block),crc);
Send(CHR(Hi(crc)));
Send(CHR(Lo(crc)));
PurgeLine;
Inc(counter);
UNTIL (readline(10) = Ord(ACK)) OR (counter = retrymax);
inc(blocknum);
UNTIL EOF(f) OR (counter = retrymax) OR (NOT Carrier);
IF counter = retrymax THEN
Writeln(CR,LF,'No ACK on sector')
ELSE
BEGIN
counter := 0;
REPEAT
Send(EOT);
Inc(counter);
UNTIL (readline(10) = Ord(ACK)) or (counter=retrymax);
IF counter = retrymax THEN
WriteLn(CR,LF,'No ACK on EOT')
ELSE WriteLn(CR,LF,'Transfer complete');
END;
(* Send a null header block to signify end of transfer! *)
counter := 0;
REPEAT
FillChar(sector,SizeOf(sector),CHR(0)); { NULL := CHR(0) }
Send(SOH);
Send(#$00);
Send(#$FF);
SendBlk(seg(sector[0]),ofs(sector[0]),128);
crc := 0;
crca(Sector, SizeOf(sector), crc);
Send(CHR(Hi(crc)));
Send(CHR(Lo(crc)));
inc(counter);
UNTIL (Readline(10) = Ord(ACK)) or (counter = retrymax);
END;
(*
PROCEDURE PackDateAndTime(var pd : date; dt : DateTime);
{ Returns the number of seconds since 00:00:00 01/01/1970 }
CONST TDays : array[boolean,0..12] of word =
((0,31,59,90,120,151,181,212,243,273,304,334,365),
(0,31,60,91,121,152,182,213,244,274,305,335,366));
diff = 347155200;
VAR total,
temp : date;
lyr : boolean;
BEGIN
lyr := (((dt.year mod 4 = 0) and (dt.year mod 100 <>0))
or (dt.year mod 400 = 0));
dec(dt.year,1981);
total := date(dt.sec) + (dt.min * 60) + (date(dt.hour) * 3600);
temp := date(dt.year) * word(365) + (dt.year div 4);
inc(temp,TDays[lyr][dt.month-1]);
inc(temp,dt.day-1);
pd := total + (temp * 86400) + diff;
END; {PackDateAndTime}
crc := 0;
crca(block, SizeOf(block), crc);
Send(CHR(Hi(crc)));
Send(CHR(Lo(crc)));
BlockCRC(Seg(block),Ofs(block),1023);
Send(CHR(Hi(crc_reg_hi)));
Send(CHR(Lo(crc_reg_hi)));
BlockCRC(Seg(sector[0]),ofs(sector[0]),127);
Send(CHR(Hi(crc_reg_hi)));
Send(CHR(Lo(crc_reg_hi)));
{FOR j := 0 TO 1023 do begin
Send(block[j]);
updcrc(tcrc,block[j]);
end;
}
*)